function getPriceNumber({ price, rule }) {
  const rate = rule.rate ? Number(rule.rate) : 1
  price = price * rate
  const priceList = price.toString().split('.')
  const number = priceList.join('')
  const digit = priceList[0].length
  const START_ASCII_NUMBER = 65
  const digitCode = String.fromCharCode(START_ASCII_NUMBER + digit - 1)
  const validNumber = number.substr(0, 3).padStart(3, '0')
  let replaceNumber = ''
  replaceNumber += rule['replace' + validNumber[0]]
  replaceNumber += rule['replace' + validNumber[1]]
  replaceNumber += rule['replace' + validNumber[2]]
  if (rule['replace' + digitCode]) {
    return rule['replace' + digitCode] + replaceNumber
  }
  return digitCode + replaceNumber
}

/**
 * 隐藏价格编号
 * @param price
 * @param rule
 * @returns {string|*}
 */
export const numberHidePrice = (price, rule) => {
  let size = 11
  if (rule && rule.size) {
    size = Number(rule.size)
  }
  const number = Math.random().toString(36).substr(2).toUpperCase().padStart(size, 'A').slice(0, size)
  if (!rule) {
    return number
  }
  const priceNumber = getPriceNumber({ price, rule })
  const numberList = number.split('')
  if (numberList[rule.pos1 - 1]) {
    numberList[rule.pos1 - 1] = priceNumber[0]
  }
  if (numberList[rule.pos2 - 1]) {
    numberList[rule.pos2 - 1] = priceNumber[1]
  }
  if (numberList[rule.pos3 - 1]) {
    numberList[rule.pos3 - 1] = priceNumber[2]
  }
  if (numberList[rule.pos4 - 1]) {
    numberList[rule.pos4 - 1] = priceNumber[3]
  }
  return numberList.join('')
}
